##
## Makefile for Makefile in /home/dubois_e//Prog/Project
## 
## Made by remi dubois
## Login   <dubois_e@epitech.net>
## 
## Started on  Thu Oct 11 19:43:03 2012 remi dubois
## Last update Sat Oct 13 21:03:08 2012 remi dubois
##

NAME			=	test

SRC_DIR			=	./src/
OBJ_DIR			=	./obj/
INC_DIR			=	./include/
LIB_DIR			=	./libs/
SRC_LIB_DIR		=	$(LIB_DIR)/src/
OBJ_LIB_DIR		=	$(LIB_DIR)/obj/

SRC			=	$(notdir $(wildcard $(SRC_DIR)/*.c))
OBJ			=	$(addprefix $(OBJ_DIR), $(patsubst %.c, %.o, $(SRC)))
INC			=	$(wildcard $(INC_DIR)/*.h)
LIB			=	$(notdir $(wildcard $(LIB_DIR)/*.a))

FLAGS_LIB_MATHS		=	-lm
FLAGS_LIB_MLX		=	-lX11
FLAGS_LIB_NCURSES	=	-lncurses
FLAGS_LIB_DIR		=	$(addprefix -L, $(LIB))				\
				$(patsubst lib%.a, -l%, $(notdir $(wilcard $(LIB_DIR)*.a)))
FLAGS_LIB		=	$(FLAGS_LIB_DIR) $(FLAGS_LIB_MATHS) $(FLAGS_LIB_MLX) $(FLAGS_LIB_NCURSES)

FLAGS_INC		=	$(addprefix -I, $(INC_DIR))

CC			=	gcc
CFLAGS			=	-W -Wall -pedantic -g3


${NAME}			:	$(OBJ)
				@$(CC) -o $(NAME) $(OBJ) $(CFLAGS) $(FLAGS_INC) $(FLAGS_LIB)
				@echo "Création de l'exécutable réussie."
				@echo "Compilation du projet réussie."

all 			:	$(NAME)

clean			:
				@rm -rf $(OBJ)
				@echo "Suppression des fichiers objets."

fclean			:	clean
				@rm -rf $(NAME)
				@echo "Suppression de l'exécutable."

re			:	fclean all

$(OBJ_DIR)%.o		:	$(SRC_DIR)%.c $(INC)
ifeq ($(LIB),)
	@(cd $(LIB_DIR) && $(MAKE))
endif
				@$(CC) -c -o $@ $< $(CFLAGS) $(FLAGS_LIB) $(FLAGS_INC)
				@echo "Création des fichiers objets réussie."